package com.gitee.ed.example.retryer;

import cn.hutool.core.text.CharSequenceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Consumer;

/**
 * @author hongda.li
 */
public class LoggerListener<Result> implements Consumer<RetryResult<Result>> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void accept(RetryResult<Result> retryResult) {
        logger.debug("--- Retry Log");
        logger.debug("--- Total retry time  : [{}]ms", retryResult.totalTime());
        logger.debug("--- Total retry count : [{}]", retryResult.totalCount());
        if (logger.isDebugEnabled() && retryResult.throwable() != null) {
            logger.debug("--- Retry error", retryResult.throwable());
        }
        logger.debug(CharSequenceUtil.EMPTY);
    }
}
